package com.xdl.flytest.util.job;

import com.xdl.flytest.bean.Task;
import com.xdl.flytest.service.TestSuitService;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @Auther: 80736
 * @Date: 2019/2/3 13:01
 * @Description:
 */

@Component
@DisallowConcurrentExecution
public class TestSuitJob implements Job {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private TestSuitService testSuitService;

    @Override
    public void execute(JobExecutionContext context) {

        logger.debug(String.format("TestSuit job starting at %s", new Date()));
        Task task = (Task) context.getJobDetail().getJobDataMap().get(Task.JOB_PARAM);
        logger.debug(String.format("execute task success : task name : %s,task run with id : %s", task.getTaskName(), task.getRunWith()));
        try {
            testSuitService.runTestSuit(task.getRunWith());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
